package com.meishij.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.jash.myutils.utils.ImageUtils;
import com.meishij.R;
import com.meishij.entry.MallSellEntry;

import java.util.List;

/**
 * Created by 肖荣 on 2016/10/15.
 */

public class MallItemShaiDanAdapter extends RecyclerView.Adapter<MallItemShaiDanAdapter.ViewHolder> {
    private Context context;
    private List<MallSellEntry.ObjBean.ShaidanBean> shaidanBeanList;

    public MallItemShaiDanAdapter(Context context, List<MallSellEntry.ObjBean.ShaidanBean> shaidanBeanList) {
        this.context = context;
        this.shaidanBeanList = shaidanBeanList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_mall_sell_shaidan_recycler_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        MallSellEntry.ObjBean.ShaidanBean shaidanBean = shaidanBeanList.get(position);
        holder.shaidan_item_icon.setImageURI(shaidanBean.getUser_info().getAvatar());
        holder.shaidan_item_name.setText(shaidanBean.getUser_info().getUser_name());
        holder.shaidan_item_time.setText(shaidanBean.getTime());
        holder.shaidan_item_summary.setText(shaidanBean.getSummary());
        List<MallSellEntry.ObjBean.ShaidanBean.ImgsBean> imgs = shaidanBean.getImgs();
        if(imgs==null){//如果没有分享图
            holder.shaidan_images_container.setVisibility(View.GONE);
        }else if(imgs!=null){
            holder.shaidan_images_container.setVisibility(View.VISIBLE);
            switch (imgs.size()) {
                case 3:
                    ImageUtils.loadImage(holder.shaidan_item_image3,imgs.get(2).getSmall(),R.mipmap.box_def_icon);
                case 2:
                    ImageUtils.loadImage(holder.shaidan_item_image2,imgs.get(1).getSmall(),R.mipmap.box_def_icon);
                case 1:
                    ImageUtils.loadImage(holder.shaidan_item_image1,imgs.get(0).getSmall(),R.mipmap.box_def_icon);
                    break;
                case 0:
                    default:
                        holder.shaidan_item_image1.setVisibility(View.GONE);
                        break;
            }
        }

    }

    @Override
    public int getItemCount() {
        return shaidanBeanList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{

        private SimpleDraweeView shaidan_item_icon;
        private TextView shaidan_item_name;
        private TextView shaidan_item_time;
        private TextView shaidan_item_summary;
        private LinearLayout shaidan_images_container;
        private ImageView shaidan_item_image1;
        private ImageView shaidan_item_image2;
        private ImageView shaidan_item_image3;
        public ViewHolder(View itemView) {
            super(itemView);
            shaidan_item_icon = ((SimpleDraweeView) itemView.findViewById(R.id.shaidan_item_icon));
            shaidan_item_name = ((TextView) itemView.findViewById(R.id.shaidan_item_name));
            shaidan_item_time = ((TextView) itemView.findViewById(R.id.shaidan_item_time));
            shaidan_item_summary = ((TextView) itemView.findViewById(R.id.shaidan_item_summary));
            //如果没图就直接GONE掉
            shaidan_images_container = ((LinearLayout) itemView.findViewById(R.id.shaidan_images_container));
            shaidan_item_image1 = ((ImageView) itemView.findViewById(R.id.shaidan_item_image1));
            shaidan_item_image2 = ((ImageView) itemView.findViewById(R.id.shaidan_item_image2));
            shaidan_item_image3 = ((ImageView) itemView.findViewById(R.id.shaidan_item_image3));
        }
    }
}
